import { Controller, Get, Param, Query, Render, Req, Res } from "@nestjs/common";
import { AppService } from "../service/app.service";
import { Request, Response } from "express";

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {
  }

  /**
   * 可以直接使用@Render来返回
   */
  @Get()
  @Render("index")
  getHello(): any {
    return this.appService.getHello();
  }

  /**
   * 根据不同的情况，通过逻辑来控制要渲染哪一个视图页面
   * @param request
   * @param response
   * @param key
   * @param keyQuery
   */
  @Get("/index")
  renderPage(@Req() request: Request, @Res() response: Response,
             @Param("key") key: string,
             @Query("key") keyQuery: string): any {
    console.log(keyQuery);
    if (keyQuery === "1") {
      return response.render("index1", this.appService.getHello());
    } else {
      return response.render("index2", this.appService.getHello());
    }

  }

}
